from core.basehandler import BaseHandler
from core.room import Room
from core.support import set_cutscene, get_game
from core.action import Action
import random

class EnterPantry(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        
        # build list of actions
        self.add_action(Exit)
        self.add_action(WordGame)
    
    
    def get_description(self):
        desc = '''You are inside the pantry. There are open, ransacked cabinets, potato chips, peanut butter, and candy bars spilled all over the floor. It looks like someone left in a hurry.'''
        return desc
    
    def get_image(self):
        return 'pantry.jpg'

class PantryHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return EnterPantry

# define actions for this room

class Exit(Action):
    def __init__(self):
        Action.__init__(self, "Exit")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Exit"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'startingpoint'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

class WordGame(Action):
    def __init__(self):
        Action.__init__(self, "WordGame")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Play Word Game"
    
    def do_action(self,game,room,request):
        words = ("destroy", "locke")
        game.wordgameanswer = random.choice(words)
        game.wordgameprompt = self.jumble(game.wordgameanswer)
        
    def jumble(self, word):
        jumble = list(word)
        random.shuffle(jumble)
        return ''.join(jumble)
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'wordgame'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"

